package info.xiao.dataStructrue.stack;

import java.util.Stack;

/**
 * @Classname MinStack 包含min函数的栈
 * @Description : https://leetcode.cn/problems/bao-han-minhan-shu-de-zhan-lcof/
 * @Date 2022/10/20 14:40
 * @Created by 晓龙Oba
 */
public class MinStack {
    // 通过数组充当内存容器
    private Stack<Integer> pot = new Stack<>();
    // 栈顶指针
    private Integer topIndex = 0;
    // 最大元素数量
    private Integer max_counts = 5;

    private Stack<Integer> minStack = new Stack<>();

    /**
     * initialize your data structure here.
     */
    public MinStack() {

    }

    public void push(int x) {
        if (pot.isEmpty()) {
            pot.push(x);
            minStack.push(x);
        } else {
            pot.push(x);
            minStack.push(minStack.peek() < x ? minStack.peek() : x);
        }
    }

    public void pop() {
        pot.pop();
        minStack.pop();
    }

    public int top() {
        return pot.peek();
    }

    public int min() {
        return minStack.peek();
    }
}



